package com.lyx.crm.config;

import com.lyx.crm.interceptor.NoLoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @Package: com.lyx.crm.config
 * @ClassName: MvcConfig
 * @Author: lyx
 * @CreateTime: 2021/7/20 12:41
 * @Description:
 */
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
    @Bean   //将方法交给IOC维护
    public NoLoginInterceptor noLoginInterceptor() {
        return new NoLoginInterceptor();
    }

    /**
     * 添加拦截器
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //需要一个实现了拦截器功能的实例对象，这里使用的是noLoginInterceptor
        registry.addInterceptor(noLoginInterceptor())
                //设置需要被拦截的资源
                .addPathPatterns("/**")
                //设置不需要被拦截的资源
                .excludePathPatterns("/css/**","/images/**","/lib/**","/js/**","/index","/user/login");
    }
}
